package convert.types;


import com.aspose.cells.FontConfigs;
import com.aspose.cells.License;
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;
import convert.AbstractToPdf;

import java.io.InputStream;
import java.io.OutputStream;

/**
 * Excel转PDF
 * <br>
 * Created by Hong 2024/7/4
 **/
public class ExcelToPdf extends AbstractToPdf {

    private final Workbook workbook;

    public ExcelToPdf(InputStream inputStream) throws Exception {
        this.workbook = new Workbook(inputStream);
    }

    @Override
    public void init() {
        License license = new License();
        license.setLicense(getLicense());
    }

    @Override
    protected void fontSettings() {
        if (System.getProperty("os.name").contains("linux")) {
            FontConfigs.setFontFolder("/usr/share/fonts/chinese", true);
        }
    }

    @Override
    public void toPdf(OutputStream outputStream) throws Exception {
        workbook.save(outputStream, SaveFormat.PDF);
    }

    @Override
    public void close() {
        if (workbook != null) {
            workbook.dispose();
        }
    }
}
